<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table{
            width: 400px;
            margin: 100px auto;
            text-align: center;
            font-size: 14px;
            border-collapse: collapse;
        }

        thead tr{
            height: 40px;
            background-color: skyblue;
        }

        tbody tr{
            height: 40px;
        }

        tbody td{
            border-bottom: 1px solid #d7d7d7;
            font-size: 12px;
        }

        .bg{
            background-color: #cdec1d;
        }
    </style>
</head>
<body>
    <table>
        <thead>
            <tr>
                <th>
                    <input type="checkbox" id="j_cbAll">
                </th>
                <th>商品</th>
                <th>价钱</th>
            </tr>
        </thead>
        <tbody id="j_tb">
            <tr>
                <td>
                    <input type="checkbox" />
                </td>
                <td>iPhone8</td>
                <td>8000</td>
            </tr>
            <tr>
                <td>
                    <input type="checkbox" /> 
                </td>
                <td>iPad Pro</td>
                <td>5000</td>
            </tr>
            <tr>
                <td>
                    <input type="checkbox" />
                </td>
                <td>iPad Air</td>
                <td>2000</td>
            </tr>
            <tr>
                <td>
                    <input type="checkbox" />
                </td>
                <td>Apple Watch</td>
                <td>2000</td>
            </tr>
        </tbody>
    </table>

    <script>
         var trs = document.querySelector('tbody').querySelectorAll('tr');

         for(var i=0; i < trs.length;i++){
            trs[i].onmouseover = function () {
                this.className = 'bg';
            }

            trs[i].onmouseout = function () {
                this.className = '';
            }
         }

         var j_cbAll = document.getElementById('j_cbAll');
         var j_tb = document.getElementById('j_tb').getElementsByTagName('input');

         j_cbAll.onclick = function() {
              for(var i=0;i < j_tb.length;i++){
                j_tb[i].checked = this.checked;
              }
         }

         for(var i=0;i < j_tb.length;i++){
            j_tb[i].onclick = function() {
                var flag = true;
                for(var i=0;i < j_tb.length;i++){
                    if(!j_tb[i].checked){
                       flag = false;
                       break;
                    }
                }
                j_cbAll.checked = flag;
            }
         }

    </script>
    
</body>
</html>